package com.zhangyu.shadow.ec.main.personal.list;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhangyu.shadow.ec.R;

import java.util.List;

/**
 * @author zhangyu
 * @date 2017/12/22
 */

public class ListMenuAdapter extends BaseMultiItemQuickAdapter<ListBean, BaseViewHolder> {
    private static final RequestOptions OPTIONS = new RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .dontAnimate()
            .centerCrop();

    public ListMenuAdapter(List<ListBean> data) {
        super(data);
        addItemType(ListItemType.ITEM_NORMAL, R.layout.item_personal_item);
        addItemType(ListItemType.ITEM_TEXT, R.layout.item_text_item);
        addItemType(ListItemType.ITEM_AVATAR, R.layout.item_avatar_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, ListBean item) {
        switch (item.getItemType()) {
            case ListItemType.ITEM_NORMAL:
                helper.setText(R.id.tv_name, item.getName());
                helper.setText(R.id.icon_header, item.getUrl());
                break;
            case ListItemType.ITEM_TEXT:
                helper.setText(R.id.tv_title, item.getName());
                helper.setText(R.id.tv_value, item.getValue());
                break;
            case ListItemType.ITEM_AVATAR:
                Glide.with(mContext)
                        .load(item.getUrl())
                        .apply(OPTIONS)
                        .into((ImageView) helper.getView(R.id.iv_avatar));
                break;
            default:
                break;
        }
    }
}
